package behavior.interpreter;

import java.time.LocalDate;
import java.time.LocalTime;

/**
 * @author lzp
 * @Date:2023/3/1
 * @description: 格式化日志语句输出
 */
public class LogUtils {


	/**
	 * 格式化输出日志
	 *
	 * @param logStr 需要格式化的日志字符串
	 * @param args   对应占位的多个字符串
	 */
	public static void info(String logStr, Object... args) {
		StringBuffer sb = new StringBuffer();
		String[] strs = logStr.split("\\{}");
		if (strs.length > 1) {
			if (args.length < strs.length - 1) {
				throw new IllegalArgumentException("参数与占位符数量不一致");
			}
			int i = 0;
			for (; i < args.length; i++) {
				sb.append(strs[i]).append(args[i].toString());
			}
			sb.append(strs[i]);
		} else {
			sb.append(logStr);
		}
		System.out.println(sb);
	}

	public static void main(String[] args) {
		LogUtils.info("[{}] start {} at {}...", LocalTime.now().withNano(0), "engine", LocalDate.now());
	}

}
